<?php

use think\migration\Seeder;

use think\facade\Db;

class License extends Seeder
{
    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * http://docs.phinx.org/en/latest/seeding.html
     */
    public function run(): void
    {
        if (!Db::name('config')->where('type', 'system')->where('key', 'license')->find()) {
            Db::name('config')->save([
                'type' => 'system',
                'key' => 'license',
                'value' => strtoupper(bin2hex(random_bytes(8))),
            ]);
        }
        if (!Db::name('config')->where('type', 'applet')->where('key', 'app_xcx')->find()) {
            $copyright = request()->scheme() . '://' . request()->host() . '/copyright.png';
            $appletModel = [
                [
                    'type' => 'applet',
                    'key' => 'app_xcx',
                    'value' => '见闻间,见闻间，让社区以全新的方式喧起来！,,见闻间，让社区以全新的方式喧起来！',
                ],
                [
                    'type' => 'applet',
                    'key' => 'app_bq',
                    'value' => '1,' . $copyright . ',见闻间提供技术支持,www.cc.chaopin100.com,https://cc.chaopin100.com',
                ]
            ];
            Db::name('config')->insertAll($appletModel);
        }
    }
}
